<?php


/**
 * 此类存放各类工具
 */

//定义常量
define("ERROR_LOGIN","login");

//加载所有模块的mod
function mods($str){
    //切割$str为数组
    $mods = explode(',',$str);
    //遍历切割完的数组,加载文件
    foreach ($mods as $mod){
        if (trim($mod) != ''){
            //如果不为空,则加载
            //例如$mod为login,则加载mods/login/login.mod
            require_once 'mods/'.trim($mod).'/'.trim($mod).'.mod';
        }else{
            echo $mod.'.mod找不到';
        }
    }
}

//加载inc
function func($str)
{
    //切割
    $funcs=explode(',', $str);
    //遍历切割完的数组,加载文
    foreach($funcs as $func) {
        //加载
        //例如$str为auth,则加载 include/auth.inc
        require_once 'include/'.trim($func).'.inc';
    }
}

//设置cookie读取的域名
function session_getCookieDomain(){
    $domain=$_SERVER['SERVER_NAME'];
    return $domain;
}

function initSession(){
    /*ini_set('session.gc_maxlifetime', "3600");
    ini_set("session.cookie_lifetime","3600");*/
    session_start();
    $data = array();
    $sql = "select * from session_data where sessionId='".session_id()."'";
    $result = $GLOBALS['DB']->query($sql);
    while($res=$result->fetch()) {
        $data = $res;
    }

    if (!empty($data)){
        $_SESSION['USERID'] = $data['userId'];
    }else{
        unset($_SESSION['USERID']);
    }
}

function logOut(){
    if (!empty($_SESSION['USERID'])){
        $sql = "delete from session_data where userId='".$_SESSION['USERID']."'";
        $GLOBALS['DB']->query($sql);
        session_unset($_SESSION['USERID']);
    }
}

//判断请求是POST还是GET
function getorPostRequest()
{
    return isset($_SERVER['REQUEST_METHOD']) && !strcasecmp($_SERVER['REQUEST_METHOD'],'POST');
}

//短信发送
function sendcloud_sendSMS($smsUser, $smsKey, $smsTemplateId, $phone, $vars)
{
    $url = 'http://www.sendcloud.net/smsapi/send';

    $param = array(
        'smsUser' => $smsUser,
        'templateId' => $smsTemplateId,
        'msgType' => '0',
        'phone' => $phone,
        'vars' => $vars
    );

    $sParamStr = "";
    ksort($param);
    foreach ($param as $sKey => $sValue) {
        $sParamStr .= $sKey . '=' . $sValue . '&';
    }

    $sParamStr = trim($sParamStr, '&');
    $sSignature = md5($smsKey."&".$sParamStr."&".$smsKey);


    $param = array(
        'smsUser' => $smsUser,
        'templateId' => $smsTemplateId,
        'msgType' => '0',
        'phone' => $phone,
        'vars' => $vars,
        'signature' => $sSignature
    );

    $data = http_build_query($param);

    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-Type:application/x-www-form-urlencoded',
            'content' => $data
        ));
    $context  = stream_context_create($options);
    $result = file_get_contents($url, FILE_TEXT, $context);

    return $result;
}


function _output_template($type,$template){

    if (!isset($template)){
        //如果为空,则加载默认
        $template = 'mods/main/tpl/main.tpl';
    }else{
        //不为空,判断是否展现移动端页面
        if ($type == 5){
            //展现移动端
            $template='mods/'.$template.'/tpl/mobile_'.$template.'.tpl';
        }else{
            //展现web端
            $template='mods/'.$template.'/tpl/'.$template.'.tpl';
        }
    }

    ob_start();
    //extract($data);
    include($template);
    ob_end_flush();
}

//测试  头部输出
/**
 * @param $curent_mod
 * @return string
 * <meta name="viewport" id="WebViewport" content="width=device-width, target-densitydpi=device-dpi, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
 */
function _output_test_header(){
    $str =
        '
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <meta http-equiv="content-type" content="text/html" charset="UTF-8"/>
                <title>碑林区政协提案办理系统</title>';

    $str = $str. '
                <link rel="stylesheet" type="text/css" href="/css/main.css"  />
                <link rel="stylesheet" type="text/css" href="/css/redactor.css"  />
                <script type="text/javascript" src="/js/jquery-3.1.1.min.js"></script>
                <script type="text/javascript" src="/js/main.js"></script>
                <script src="/js/dist/circleChart.min.js"></script>
                <script src="/js/redactor.js"></script>';
    $str = $str.'</head>
            <body>
        ';
    return $str;
}

function _output_test_body(){
    $str = '<div>哈哈哈哈哈哈哈哈哈哈</div>';
    return $str;
}

//测试  尾部输出
function _output_test_footer(){
    $str ='
            </body>
        </html>';
    return $str;
}
//标题
function _output_title(){
    if (empty($_SESSION['USERID'])){
        $str="
             <div class='main_title_icon'> </div>
             <div class='main_title_text'>碑林区政协提案办理系统</div>
             <div class='main_title_right'>
                 <div class='main_tilte_right_avtar' style='background-image: url(/images/main/touxiang1.png);'>
                 
                <ul class='main_url' style='width: 170px;height: 165px;position: absolute;top:65px;right:-120px;background-image: url(/images/main/diban.png);background-size: 170px 165px;background-repeat: no-repeat;border-radius: 8px;display: none;'> 
                    <li class='li_qhzh' id='main_04' style='margin-top:5px ' onclick='showqhzhdialog()' >切换账号</li>
                    <li class='li_xgmm' id='main_05' onclick='showxgmidialog()'>修改登录密码</li>
                    <li class='main_li_none'  id='main_06' onclick='showbjzldialog()'>编辑个人资料</li>
                </ul>
                <style>
                    .main_url{list-style-type: none}
                    .main_url li{color: #4e99ff;height:50px;text-align: center;line-height:50px;cursor:pointer;border-bottom:1px solid #f5faff;border-radius: 8px}
                    .main_li_none{color: #4e99ff;height:50px;text-align: center;line-height:50px;cursor:pointer;}
                    .sub li.hover{background:#8b8b8b;}
                </style>
                <script type='text/javascript'>
                $('.main_tilte_right_avtar').click(
                    function() {
                      $('.main_url').css('display')=='none' ? $ ('.main_url').css('display','block'):$('.main_url').css('display','none');
                    }
                );
                $('.main_url li').each(
                    function() {
                      $(this).mouseover(function() {
                        $(this).css('background-color','#4e99ff');
                        $(this).css('color','#fff');
                      });
                      $(this).mouseout(function() {
                        $(this).css('background-color','#fff');
                        $(this).css('color','#4e99ff');
                      });
                    }
                );
                
                </script>
                </div>
                 <div class='main_title_right_text'>孟天 - 提案委</div>
                 <div class='main_title_right_noice'></div>
                 <div class='main_title_right_exit'></div>
             </div>
             ";
    }else{
        $str="
             <div class='main_title_icon'> </div>
             <div class='main_title_text'>碑林区政协提案办理系统</div>
             <div class='main_title_right'>
                <div class='main_tilte_right_avtar' id='".$GLOBALS['USERINFO']['id']."' style='border-radius: 15px;background-image: url(images/main/22.png)'>
                 
                <ul class='main_url' style='width: 170px;height: 165px;position: absolute;top:65px;right:-120px;
                background-image: url(/images/main/diban.png);background-size: 170px 165px; 
                background-repeat: no-repeat;border-radius: 8px;display: none;'> 
                            <li style='margin-top:5px' id='main_04' onclick='showqhzhdialog()'>切换账号</li>
                            <li id='main_05' onclick='showxgmidialog()'>修改登录密码</li>
                            <li class='main_li_none' id='main_06' onclick='showbjzldialog()'>编辑个人资料</li>
                </ul>
                <style>
                    .main_url{list-style-type: none}
                    .main_url li{color: #4e99ff;height:50px;text-align: center;line-height:50px;cursor:pointer;border-bottom:1px solid #f5faff;border-radius: 8px}
                    .main_li_none{color: #4e99ff;height:50px;text-align: center;line-height:50px;cursor:pointer;}
                    .sub li.hover{background:#8b8b8b;}
                </style>
                <script type='text/javascript'>
                    $('.main_tilte_right_avtar').click(
                        function() {
                          $('.main_url').css('display')=='none' ? $ ('.main_url').css('display','block'):$('.main_url').css('display','none');
                        }
                    );
                    $('.main_url li').each(
                        function() {
                          $(this).mouseover(function() {                     
                            $(this).css('background-color','#4e99ff');
                             $(this).css('color','#fff');
                          });
                          $(this).mouseout(function() {
                            $(this).css('background-color','#fff');
                             $(this).css('color','#4e99ff');
                          });
                        }
                    );
                </script>
                </div>
                 <div class='main_title_right_text'>".$GLOBALS['USERINFO']['realname']."</div>
                 <div class='main_title_right_noice' style='cursor: pointer'></div>
                 <div class='main_title_right_exit' style='cursor: pointer'></div>
                 <script>
                    $('.main_title_right_noice').click(function() {
                       window.location.href = '?action=xinxi';
                    });
                    $('.main_title_right_exit').click(function() {
                       window.location.href = '?action=login';
                    });
                 </script>
             </div>
             ";
    }

    return $str;
}

//导航
//定义nav
function _output_nav(){
    $str="<div style='padding-top: 15px'> ";
    $menuArr = array();
    $user = getUserInfo($GLOBALS['USERINFO']['id']);
    $user['role'];
    $userGroup = getAllUserGroup();
    foreach ($userGroup as $value){
        if ($value['id'] === $user['role']){
            //0为无权限 1为有权限
            $value['homepage'] === '1' ? $menuArr['homepage'] = array("name"=>"首页","action"=>"?action=main","type"=>"main","remind"=>"0","class"=>""): '';
            $value['myproposal'] === '1' ? $menuArr['myproposal'] = array("name"=>"我的提案","action"=>"?action=wode","type"=>"wode","remind"=>"0","class"=>""): '';
            $value['createproposal'] === '1' ? $menuArr['createproposal'] = array("name"=>"新建提案","action"=>"?action=xinjian","type"=>"xinjian","remind"=>"0","class"=>""): '';
            $value['daifankuiproposal'] === '1' ? $menuArr['daifankuiproposal'] = array("name"=>"待反馈提案","action"=>"?action=daifankui","type"=>"daifankui","remind"=>"0","class"=>"remind_daifankui"): '';
            $value['shenchaproposal'] === '1' ? $menuArr['shenchaproposal'] = array("name"=>"审查提案","action"=>"?action=shencha","type"=>"shencha","remind"=>"12","class"=>"remind_shencha"): '';
            $value['jiaobanproposal'] === '1' ? $menuArr['jiaobanproposal'] = array("name"=>"交办提案","action"=>"?action=jiaoban","type"=>"jiaoban","remind"=>"0","class"=>"remind_jiaoban"): '';
            $value['banliproposal'] === '1' ? $menuArr['banliproposal'] = array("name"=>"办理提案","action"=>"?action=banli","type"=>"banli","remind"=>"32","class"=>"remind_banli"): '';
            $value['yibanproposal'] === '1' ? $menuArr['yibanproposal'] = array("name"=>"已办提案","action"=>"?action=yiban","type"=>"yiban","remind"=>"0","class"=>""): '';
            $value['suoyouproposal'] === '1' ? $menuArr['suoyouproposal'] = array("name"=>"所有提案","action"=>"?action=suoyou","type"=>"suoyou","remind"=>"0","class"=>""): '';
            $value['weiyuaninfo'] === '1' ? $menuArr['weiyuaninfo'] = array("name"=>"委员信息","action"=>"?action=weiyuan","type"=>"weiyuan","remind"=>"0","class"=>""): '';
            $value['message'] === '1' ? $menuArr['message'] = array("name"=>"消息中心","action"=>"?action=xinxi","type"=>"xinxi","remind"=>"0","class"=>"remind_xinxi"): '';
            $value['manager'] === '1' ? $menuArr['manager'] = array("name"=>"系统管理","action"=>"?action=xitong","type"=>"xitong","remind"=>"0","class"=>""): '';
        }
    }

    foreach ($menuArr as $value){
        if($value['type']===$GLOBALS['ACTION']){
            $str=$str."
                <a href='".$value['action']."' class='main_bottom_left_a'>
                   <div class='main_botton_left_text'> 
                    ".$value['name']."
                    ";
                    $str=$str."<div class='".$value['class']."' style='background-color: red;
                                                                            width:20px;
                                                                            height: 20px;
                                                                            color: white;
                                                                            font-size: 10px;
                                                                            border-radius: 180px;
                                                                            line-height: 21px;
                                                                            float: right;
                                                                            margin: auto;
                                                                            position: relative;
                                                                            top: 15px;
                                                                            right: 20px;
                                                                            z-index: 9999;
                                                                            display: none;
                                                                            text-indent: 0px;
                                                                            text-align: center;'>
                   ".$value['remind']."
                   </div></div></a>";

        }else{
            $str=$str."
                <a href='".$value['action']."' class='main_bottom_left_a'>
                   <div class='main_botton_left_text_no'> 
                    ".$value['name']."";
                $str=$str."<div class='".$value['class']."' style='background-color: red;
                                                                            width:20px;
                                                                            height: 20px;
                                                                            color: white;
                                                                            font-size: 10px;
                                                                            border-radius: 180px;
                                                                            line-height: 21px;
                                                                            float: right;
                                                                            margin: auto;
                                                                            position: relative;
                                                                            top: 15px;
                                                                            right: 20px;
                                                                            z-index: 9999;
                                                                            display: none;
                                                                            text-indent: 0px;
                                                                            text-align: center;'>
                   ".$value['remind']."
                   </div></div></a>";

        }
    };
    return $str."</div>
                 <script>getNavNum();</script>";
}

function output_tab(){
    if (empty($_REQUEST['page'])){
        $page = 1;
    }else{
        $page = $_REQUEST['page'];
    }

    $str = "               
                    </div>
                </div>
                <div style='min-height: 750px;width: 100%;height: 85%;margin-top:3%;'>
                    <div class='datalist' id='".$page."' style='height: 90%;'>
                    </div>
                    
                    <div  style='height: 10%; position: relative'>
                        <div  style='display: inline-block;position: absolute;top: 28%;left: 50%;transform: translateX(-50%)'>
                            <div class='listtab' style='display: inline-block'>
                                
                            </div>
                        </div>
                    </div>
                    <script>getDataList('')</script>
                </div>
            </div>";
    return $str;
}

function output_tab_2($entryCount,$curentpage,$mod){
    if ($entryCount%12 > 0){
        $num = $entryCount - $entryCount%12;
        $pageCount = ($num / 12) + 1;
    }else{
        $pageCount = $entryCount/12;
    }

    if ($mod == 2){
        $str = '<div style="position: relative;left: 50%;top: 20%;transform: translateX(-50%);display: inline-block">
               <ul style="list-style: none;height: 40px;display: inline-block;position: relative;left: 50%;transform: translateX(-50%);">
                    <a href="?action='.$GLOBALS['ACTION'].'&page='.($curentpage <= 1 ? 1:$curentpage-1).'&manager='.$mod.'"><li style="text-align:center;width: 60px;height: 40px;float: left;font-size: 16px;color: #999;line-height: 40px;border: 1px solid #dcdcdc;border-radius: 4px">上一页</li></a>';
        for ($i=1;$i<=$pageCount;$i++){
            $i >= $curentpage-5 && $i <= $curentpage+5  ? $str.='<a href="?action='.$GLOBALS['ACTION'].'&page='.$i.'&manager='.$mod.'"><li style="background-color: '.($curentpage == $i ? '#4e99ff':'#fff').';margin-left: 10px;width: 40px;height: 40px;float: left;font-size: 16px;color: '.($curentpage == $i ? '#fff':'#999').';text-align: center;line-height: 40px;border: 1px solid #dcdcdc;border-radius: 4px">'.$i.'</li></a>':'';
        }
        $str.='<a href="?action='.$GLOBALS['ACTION'].'&page='.($curentpage >= $pageCount ? $pageCount:$curentpage+1).'&manager='.$mod.'"><li style="margin-left: 10px;text-align:center;width: 60px;height: 40px;float: left;font-size: 16px;color: #999;line-height: 40px;border: 1px solid #dcdcdc;border-radius: 4px">下一页</li></a>
               </ul>
           </div>';
    }else{
        $str = '<div style="position: relative;left: 50%;top: 20%;transform: translateX(-50%);display: inline-block">
               <ul style="list-style: none;height: 40px;display: inline-block;position: relative;left: 50%;transform: translateX(-50%);">
                    <a href="?action='.$GLOBALS['ACTION'].'&page='.($curentpage <= 1 ? 1:$curentpage-1).'"><li style="text-align:center;width: 60px;height: 40px;float: left;font-size: 16px;color: #999;line-height: 40px;border: 1px solid #dcdcdc;border-radius: 4px">上一页</li></a>';
        for ($i=1;$i<=$pageCount;$i++){
            $i >= $curentpage-5 && $i <= $curentpage+5  ? $str.='<a href="?action='.$GLOBALS['ACTION'].'&page='.$i.'"><li style="background-color: '.($curentpage == $i ? '#4e99ff':'#fff').';margin-left: 10px;width: 40px;height: 40px;float: left;font-size: 16px;color: '.($curentpage == $i ? '#fff':'#999').';text-align: center;line-height: 40px;border: 1px solid #dcdcdc;border-radius: 4px">'.$i.'</li></a>':'';
        }
        $str.='<a href="?action='.$GLOBALS['ACTION'].'&page='.($curentpage >= $pageCount ? $pageCount:$curentpage+1).'"><li style="margin-left: 10px;text-align:center;width: 60px;height: 40px;float: left;font-size: 16px;color: #999;line-height: 40px;border: 1px solid #dcdcdc;border-radius: 4px">下一页</li></a>
               </ul>
           </div>';
    }

    return $str;
}


function redactor($id, $air=false)
{
    $mode='';
    if($air)
        $mode='air: true,';


    $str='<script type="text/javascript">
	$(document).ready(
		function()
		{
			$("#'.$id.'").redactor({
				'.$mode.'
				buttonSource: true,
				autoresize: false,
				plugins: ["imagemanager", "filemanager", "table", "video", "fontsize", "fontcolor", "emote"],
				buttons: [ "formatting", "bold", "italic", "fontsize", "fontcolor", "backcolor", "unorderedlist", "orderedlist", "outdent", "indent", "table", "link", "image", "file", "video", "emote"]
			});
		}
	);


if (!RedactorPlugins) var RedactorPlugins = {};

RedactorPlugins.emote = function()
{
    return {
        init: function ()
        {
            var dropdown = {};
 				'.get_smileys().'
            var button = this.button.add("emote", "表情");
            this.button.setAwesome("emote", "fa-tasks");

            this.button.addDropdown(button, dropdown);
        },
        emoteCallback: function(buttonName)
        {
           	$("#'.$id.'").redactor("insert.html", "<img src=\"http://static.sparktech.cn/smileys/"+buttonName+".png\">");
        }
    };
};
function emoteCallback(obj, e, key)
{
	obj.$editor.focus();
	obj.execCommand("inserthtml", key.title);
}
	</script>';
    return $str;
}


function get_smileys()
{
    $smileys=smileys();
    $str='';
    foreach($smileys as $key=>$value)
        $str.='dropdown.'.$key.' = { title:"<img src=\"'.str_replace('/', '\/', $value['url']).'\">", func: this.emote.emoteCallback };';
    return $str;
}
function smileys()
{
    $smileys=array(
        'smile'=>array('url'=>'http://static.sparktech.cn/smileys/smile.png', 'name'=>'微笑'),
        'cute'=>array('url'=>'http://static.sparktech.cn/smileys/cute.png', 'name'=>'可爱'),
        'wink'=>array('url'=>'http://static.sparktech.cn/smileys/wink.png', 'name'=>'眨眼'),
        'giggle'=>array('url'=>'http://static.sparktech.cn/smileys/giggle.png', 'name'=>'偷笑'),
        'grin'=>array('url'=>'http://static.sparktech.cn/smileys/grin.png', 'name'=>'咧嘴笑'),
        'laugh'=>array('url'=>'http://static.sparktech.cn/smileys/laugh.png', 'name'=>'大笑'),
        'clap'=>array('url'=>'http://static.sparktech.cn/smileys/clap.png', 'name'=>'拍手'),
        'sweat'=>array('url'=>'http://static.sparktech.cn/smileys/sweat.png', 'name'=>'流汗'),
        'shock'=>array('url'=>'http://static.sparktech.cn/smileys/shock.png', 'name'=>'震惊'),
        'shout'=>array('url'=>'http://static.sparktech.cn/smileys/smile.png', 'name'=>'大喊'),
        'angry'=>array('url'=>'http://static.sparktech.cn/smileys/angry.png', 'name'=>'生气'),
        'reallyangry'=>array('url'=>'http://static.sparktech.cn/smileys/reallyangry.png', 'name'=>'愤怒'),
        'reallypissed'=>array('url'=>'http://static.sparktech.cn/smileys/reallypissed.png', 'name'=>'大怒'),
        'question'=>array('url'=>'http://static.sparktech.cn/smileys/question.png', 'name'=>'疑问'),
        'dontknow'=>array('url'=>'http://static.sparktech.cn/smileys/dontknow.png', 'name'=>'不知道'),
        'confused'=>array('url'=>'http://static.sparktech.cn/smileys/confused.png', 'name'=>'迷惑'),
        'dazed'=>array('url'=>'http://static.sparktech.cn/smileys/dazed.png', 'name'=>'迷茫'),
        'hypnotized'=>array('url'=>'http://static.sparktech.cn/smileys/hypnotized.png', 'name'=>'晕'),
        'worship'=>array('url'=>'http://static.sparktech.cn/smileys/worship.png', 'name'=>'膜拜'),
        'frownbig'=>array('url'=>'http://static.sparktech.cn/smileys/frownbig.png', 'name'=>'委屈'),
        'frown'=>array('url'=>'http://static.sparktech.cn/smileys/frown.png', 'name'=>'难过'),
        'weep'=>array('url'=>'http://static.sparktech.cn/smileys/weep.png', 'name'=>'流泪'),
        'crying'=>array('url'=>'http://static.sparktech.cn/smileys/crying.png', 'name'=>'大哭'),
        'beatup'=>array('url'=>'http://static.sparktech.cn/smileys/beatup.png', 'name'=>'挨揍'),
        'inlove'=>array('url'=>'http://static.sparktech.cn/smileys/inlove.png', 'name'=>'喜欢'),
        'kiss'=>array('url'=>'http://static.sparktech.cn/smileys/kiss.png', 'name'=>'亲亲'),
        'arrogant'=>array('url'=>'http://static.sparktech.cn/smileys/arrogant.png', 'name'=>'傲慢'),
        'cool'=>array('url'=>'http://static.sparktech.cn/smileys/cool.png', 'name'=>'酷'),
        'yawn'=>array('url'=>'http://static.sparktech.cn/smileys/yawn.png', 'name'=>'哈欠'),
        'sleepy'=>array('url'=>'http://static.sparktech.cn/smileys/sleepy.png', 'name'=>'睡觉'),
        'shutmouth'=>array('url'=>'http://static.sparktech.cn/smileys/shutmouth.png', 'name'=>'闭嘴'),
        'bye'=>array('url'=>'http://static.sparktech.cn/smileys/bye.png', 'name'=>'再见'),
        'thumbsup'=>array('url'=>'http://static.sparktech.cn/smileys/thumbsup.png', 'name'=>'牛'),
        'thumbsdown'=>array('url'=>'http://static.sparktech.cn/smileys/thumbsdown.png', 'name'=>'弱'),
        'handshake'=>array('url'=>'http://static.sparktech.cn/smileys/handshake.png', 'name'=>'握手'),
        'heart'=>array('url'=>'http://static.sparktech.cn/smileys/heart.png', 'name'=>'爱心'),
        'heartbroken'=>array('url'=>'http://static.sparktech.cn/smileys/heartbroken.png', 'name'=>'心碎'),
        'rose'=>array('url'=>'http://static.sparktech.cn/smileys/rose.png', 'name'=>'玫瑰'),
        'present'=>array('url'=>'http://static.sparktech.cn/smileys/present.png', 'name'=>'礼物'),
        'cake'=>array('url'=>'http://static.sparktech.cn/smileys/cake.png', 'name'=>'蛋糕'),
        'rainbow'=>array('url'=>'http://static.sparktech.cn/smileys/rainbow.png', 'name'=>'彩虹'),
        'drink'=>array('url'=>'http://static.sparktech.cn/smileys/drink.png', 'name'=>'饮料'),
        'beer'=>array('url'=>'http://static.sparktech.cn/smileys/beer.png', 'name'=>'啤酒'),
        'poop'=>array('url'=>'http://static.sparktech.cn/smileys/poop.png', 'name'=>'便便'),
        'bomb'=>array('url'=>'http://static.sparktech.cn/smileys/bomb.png', 'name'=>'炸弹'),
        'rain'=>array('url'=>'http://static.sparktech.cn/smileys/rain.png', 'name'=>'下雨'),
        'announce'=>array('url'=>'http://static.sparktech.cn/smileys/announce.png', 'name'=>'广播'),
        'pig'=>array('url'=>'http://static.sparktech.cn/smileys/pig.png', 'name'=>'猪头')
    );
    return $smileys;
}





/**
 * @param $message 信息
 * @param $userId 用户ID
 * @param $proposalId 提案ID
 * @param $action 模块
 * @param $type 属于哪个mod, 1公告  2任务 3私聊 4群组
 */
function sendTask($message,$userId,$proposalId,$action,$type,$groupid){
    $tasktime = date("Y-m-d H:i:s",time());
    $sql = "insert into task values(null,'".$tasktime."','".$message."',2,0,".$userId.",".$proposalId.",".$type.",'".$action."',".$groupid.",'','','')";
    $GLOBALS['DB']->query($sql);
}

function updateLookState($taskid){
    $sql = "update task set isLook=1 where id=".$taskid;
    $GLOBALS['DB']->query($sql);
}

function test(){
    //创建对象
    $excel = new PHPExcel();
    //Excel表格式,这里简略写了8列
    $letter = array('A','B','C','D','E','F','F','G');
    //表头数组
    $tableheader = array('学号','姓名','性别','年龄','班级');
    //填充表头信息
    for($i = 0;$i < count($tableheader);$i++) {
        $excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
    }
    //表格数组
    $data = array(
        array('1','小王','男','20','100'),
        array('2','小李','男','20','101'),
        array('3','小张','女','20','102'),
        array('4','小赵','女','20','103')
    );
    //填充表格信息
    for ($i = 2;$i <= count($data) + 1;$i++) {
        $j = 0;
        foreach ($data[$i - 2] as $key=>$value) {
            $excel->getActiveSheet()->setCellValue("$letter[$j]$i","$value");
            $j++;
        }
    }
    //创建Excel输入对象
    $write = new PHPExcel_Writer_Excel5($excel);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
    header("Content-Type:application/force-download");
    header("Content-Type:application/vnd.ms-execl");
    header("Content-Type:application/octet-stream");
    header("Content-Type:application/download");;
    header('Content-Disposition:attachment;filename="testdata.xls"');
    header("Content-Transfer-Encoding:binary");
    $write->save('php://output');
}

/**
 * 创建Excel
 * @param $tableheader 表头数组 ->array(title1,title2,title3,title4,title5.......)
 * @param $data 表格数组 ->array(array(),array(),......)
 */
function outputExcel($tableheader,$data,$filename){
    $excel = new PHPExcel();
    $letter = array('A','B','C','D','E','F','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
    //$letter = array('A','B','C','D','E','F','F','G');
    for($i = 0;$i < count($tableheader);$i++) {
        $excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
    }

    for ($i = 2;$i <= count($data) + 1;$i++) {
        $j = 0;
        foreach ($data[$i - 2] as $key=>$value) {
            $excel->getActiveSheet()->setCellValue("$letter[$j]$i","$value");
            $j++;
        }
    }

    $write = new PHPExcel_Writer_Excel5($excel);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
    header("Content-Type:application/force-download");
    header("Content-Type:application/vnd.ms-execl");
    header("Content-Type:application/octet-stream");
    header("Content-Type:application/download");;
    header('Content-Disposition:attachment;filename="'.$filename.'.xls"');
    header("Content-Transfer-Encoding:binary");
    $write->save('php://output');

}

/**
 * @param $url
 * @param string $path
 */
function download($url, $path = 'images/')
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    $file = curl_exec($ch);
    curl_close($ch);
    $filename = pathinfo($url, PATHINFO_BASENAME);
    $resource = fopen($path . $filename, 'a');
    fwrite($resource, $file);
    fclose($resource);
}

?>